package com.tx.test.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class CityJSONServlet
 */
public class CityJSONServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CityJSONServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		int start = Integer.parseInt(request.getParameter("start"));
		int limit = Integer.parseInt(request.getParameter("limit"));
		System.out.println("start:" + start + ",limit:" + limit);
		String json = "[{cityValue:1, cityName:'beijing'}," +
				"{cityValue:2, cityName:'shanghai'}," +
				"{cityValue:3, cityName:'shenzhen'}," +
				"{cityValue:4, cityName:'guangdong'}]";
		String pageData = "{totalProperty:4, root:" + json + "}";
//		out.println(json);
		out.println(pageData);
		out.flush();
		out.close();
	}

}
